//
//  TrialViewController.m
//  LoveTrail
//
//  Created by giantumbrella on 15/6/3.
//  Copyright (c) 2015年 赵娟. All rights reserved.
//

#import "TrialViewController.h"
#import "CommonMacro.h"
#import "TrialViewCell.h"
#import "PopViewController.h"
#import "DetailTrialViewController.h"
#import "TrialModel.h"
@interface TrialViewController ()
{
    
    NSMutableArray * faluseArray;
  
   PopViewController *popVC;
}
@property (nonatomic,strong) TrialModel *trialModel;
@end

@implementation TrialViewController

- (NSMutableArray *)allModelArray
{
    if (_allModelArray==nil) {
        _allModelArray = [NSMutableArray new];
    }
    return _allModelArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
        faluseArray = [NSMutableArray new];
    
    
    faluseArray = [@[@{@"shopName":@"雅培官方旗舰店",@"shopImg":@"http://www.mmisy.com/data/upload/shop/brand/04867319318214270_sm.jpg",@"activityImg":@"http://www.mmisy.com/data/upload/shop/editor/web-101-102-2-3.jpg?883",@"enterNum":@"396",@"lessNum":@"50",@"activityName":@"原产美国雅培精装婴幼儿奶粉试用",@"oldPrice":@"￥395"},
       @{@"shopName":@"雅培官方旗舰店",@"shopImg":@"http://www.mmisy.com/data/upload/shop/brand/04867319318214270_sm.jpg",@"activityImg":@"http://www.mmisy.com/data/upload/shop/editor/web-101-102-2-3.jpg?883",@"enterNum":@"396",@"lessNum":@"50",@"activityName":@"原产美国雅培精装婴幼儿奶粉试用",@"oldPrice":@"￥395"},
       @{@"shopName":@"雅培官方旗舰店",@"shopImg":@"http://www.mmisy.com/data/upload/shop/brand/04867319318214270_sm.jpg",@"activityImg":@"http://www.mmisy.com/data/upload/shop/editor/web-101-102-2-3.jpg?883",@"enterNum":@"396",@"lessNum":@"50",@"activityName":@"原产美国雅培精装婴幼儿奶粉试用",@"oldPrice":@"￥395"},
                    ] mutableCopy];
    
    
    for (int i = 0; i<faluseArray.count; i++) {
        self.trialModel = [[TrialModel alloc] init];
        [self.trialModel decodedic:faluseArray[i]];
        [self.allModelArray addObject:self.trialModel];
    }
    [self.tableView reloadData];
    
    //popView
     popVC = [[PopViewController alloc] init];
    
    //摆放tabBar和Search
    [self addSubViews];
    
}


#pragma mark 弹出视图 跳出菜单

-(void)popView:(UIBarButtonItem *)sender
{
    [popVC popView];
}

#pragma mark 摆放tabBar和Search
- (void)addSubViews
{
    //左侧按钮
    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"head_type"]  style:UIBarButtonItemStyleDone target:self action:@selector(popView:)];
    self.navigationItem.leftBarButtonItem = leftButton;
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    self.navigationItem.rightBarButtonItem = nil;
    //搜索栏
    self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0f,10, SCREEN_WIDTH*120.320, 40.0f)];
    self.searchBar.delegate =self;
    self.searchBar.placeholder = @"搜索";
    self.searchBar.showsCancelButton = NO;
    self.searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
    self.searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;
    self.searchBar.keyboardType = UIKeyboardTypeDefault;
    self.navigationItem.titleView = self.searchBar;
    
    //添加tableView
    //搜索结果列表
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,SCREEN_WIDTH,SCREEN_HEIGHT)];
    self.tableView.delegate =self;
    self.tableView.dataSource = self;
    //    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
    
}

//搜索栏取消键取消第一响应
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
    [self.searchBar resignFirstResponder];
}

#pragma mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return [self.allModelArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *ID = @"Cell";
    TrialViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    if (cell == nil) {
        cell = [[TrialViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    
    cell.backgroundColor = UIColorWithRGBA(242, 242, 242, 1);
    TrialModel *model = self.allModelArray[indexPath.row];
    cell.trialModel = model;
    return cell;
    
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    DetailTrialViewController *DetailTrailView = [DetailTrialViewController new];
    UINavigationController *naviDetailView = [[UINavigationController alloc] initWithRootViewController:DetailTrailView];
    [self.navigationController presentViewController:naviDetailView animated:YES completion:nil];
#warning 数据的传递是在这里进行
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 260;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


@end
